import sys
import os
from PIL import Image


TARGET_SIZE = [
    (32, 32),
    (64, 64),
    (128, 128),
    (256, 256),
    (512, 512),
]

def resize_image(image_path, rec):
    im = Image.open(image_path)
    im_resized = im.resize((rec[0], rec[1]))
    ext = os.path.basename(image_path).split(".")[1]
    target = f'{rec[0]}x{rec[1]}.{ext}'
    im_resized.save(target)

def save_as_ico(image_path):
    im = Image.open(image_path)
    im.save("logo.ico", format='ICO')

if __name__ == '__main__':
    image_path = sys.argv[1]

    save_as_ico(image_path)
    for rec in TARGET_SIZE:
        resize_image(image_path, rec)
